package com.rbac.admin.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.rbac.admin.entity.SysPermission;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 权限Mapper接口
 */
@Mapper
public interface SysPermissionMapper extends BaseMapper<SysPermission> {
    //根据方法名写 sql
    //写出对应的SQL语句
    @Select("SELECT DISTINCT p.* FROM sys_user_role ur " +
            "LEFT JOIN sys_role_permission rp ON ur.role_id = rp.role_id " +
            "LEFT JOIN sys_permission p ON rp.permission_id = p.id " +
            "WHERE ur.user_id = #{userId} AND p.status = 1 AND p.deleted = 0 " +
            "ORDER BY p.sort_order")
    List<SysPermission> selectPermissionsByUserId(Long userId);
}